package com.niuwa.p2p.action.customer;

import java.util.List;
import java.util.Map;

import org.apache.struts2.convention.annotation.Action;
import org.springframework.beans.factory.annotation.Autowired;

import com.niuwa.p2p.action.JsonAction;
import com.niuwa.p2p.core.mvc.entity.PageBean;
import com.niuwa.p2p.entity.customer.BaseCustomer;
import com.niuwa.p2p.entity.customer.Customer;
import com.niuwa.p2p.entity.customer.CustomerCompany;
import com.niuwa.p2p.entity.customer.CustomerContactor;
import com.niuwa.p2p.entity.customer.CustomerEducation;
import com.niuwa.p2p.entity.customer.CustomerHonour;
import com.niuwa.p2p.service.customer.IBaseCustomerService;
import com.niuwa.p2p.service.customer.ICustomerCompanyService;
import com.niuwa.p2p.service.customer.ICustomerContactorService;
import com.niuwa.p2p.service.customer.ICustomerEduService;
import com.niuwa.p2p.service.customer.ICustomerHonourService;
import com.niuwa.p2p.service.customer.ICustomerService;
import com.niuwa.p2p.vo.customer.BaseCustomerInfoVo;

public class RegisterCustomerAction extends JsonAction {

	private static final long serialVersionUID = -1912150173585271069L;

	private String custId;

	@Autowired
	private ICustomerService customerService;

	@Autowired
	private IBaseCustomerService baseCustomerService;

	@Autowired
	private ICustomerEduService customerEduService;

	@Autowired
	private ICustomerHonourService custHonourService;

	@Autowired
	private ICustomerCompanyService custCompanyService;

	@Autowired
	private ICustomerContactorService custContactorService;

	private Customer customer;

	private BaseCustomer baseCustomer;

	private BaseCustomer refCustomer;

	private List<CustomerEducation> custEduList;

	private List<CustomerHonour> custHonourList;

	private List<CustomerCompany> custCompanyList;

	private List<CustomerContactor> custContactorList;

	/**
	 * by zhangbo at 2015/2/5 <br>
	 * 
	 * 跳转到注册用户查询页面
	 * 
	 * @return String
	 */
	@Action("gotoRegUserListPage")
	public String gotoRegUserListPage() {
		return "regUserListPage";
	}

	@Override
	@Action("regUsersList")
	public String list() {

		Map<String, Object> paramMap = getParamMap();

		String startDate = (String) paramMap.get("startDate");
		if (null != startDate && !"".equals(startDate))
			paramMap.put("startDate", startDate.concat(" 00:00:00"));

		String endDate = (String) paramMap.get("endDate");
		if (null != endDate && !"".equals(endDate))
			paramMap.put("endDate", endDate.concat(" 23:59:59"));

		PageBean<BaseCustomerInfoVo> pagination = customerService
				.searchRegUsersList(paramMap);

		setObjectReSult(pagination);

		return NONE;
	}

	/**
	 * by zhangbo at 2015/2/5 <br>
	 * 
	 * 跳转到用户详情页
	 * 
	 * @return String
	 */
	@Action("gotoUserDetailsPage")
	public String gotoUserDetailsPage() {

		if (null != custId && !"".equals(custId)) {

			Long _custId = Long.valueOf(custId);

			// 根据用户ID获取客户信息
			customer = customerService.getCustomerById(_custId);

			// 获取推荐人信息
			long refCustId = customer.getReferee();
			refCustomer = baseCustomerService.getBaseCustInfoById(refCustId);

			// 根据用户ID获取用户基本信息
			baseCustomer = baseCustomerService.getBaseCustInfoById(_custId);

			// 获取用户院校信息列表
			custEduList = customerEduService.getCustomerEdu(_custId);

			// 获取比赛信息
			custHonourList = custHonourService.getCustHonourList(_custId);

			// 获取工作单位信息
			custCompanyList = custCompanyService.getCustCompayList(_custId);

			// 获取客户联系人信息
			custContactorList = custContactorService
					.getCustContactorList(_custId);
		}

		return "userDetailsPage";
	}

	/**
	 * by zhangbo at 2015/2/5 <br>
	 * 
	 * 跳转到用户详情页
	 * 
	 * @return String
	 */
	@Action("gotoWebUserMamage")
	public String gotoWebUserMamage() {
		return "regUserListPage";
	}

	public Customer getCustomer() {
		return customer;
	}

	public void setCustomer(Customer customer) {
		this.customer = customer;
	}

	public BaseCustomer getBaseCustomer() {
		return baseCustomer;
	}

	public void setBaseCustomer(BaseCustomer baseCustomer) {
		this.baseCustomer = baseCustomer;
	}

	public BaseCustomer getRefCustomer() {
		return refCustomer;
	}

	public void setRefCustomer(BaseCustomer refCustomer) {
		this.refCustomer = refCustomer;
	}

	public List<CustomerEducation> getCustEduList() {
		return custEduList;
	}

	public void setCustEduList(List<CustomerEducation> custEduList) {
		this.custEduList = custEduList;
	}

	public List<CustomerHonour> getCustHonourList() {
		return custHonourList;
	}

	public void setCustHonourList(List<CustomerHonour> custHonourList) {
		this.custHonourList = custHonourList;
	}

	public List<CustomerCompany> getCustCompanyList() {
		return custCompanyList;
	}

	public void setCustCompanyList(List<CustomerCompany> custCompanyList) {
		this.custCompanyList = custCompanyList;
	}

	public List<CustomerContactor> getCustContactorList() {
		return custContactorList;
	}

	public void setCustContactorList(List<CustomerContactor> custContactorList) {
		this.custContactorList = custContactorList;
	}

	public String getCustId() {
		return custId;
	}

	public void setCustId(String custId) {
		this.custId = custId;
	}
}
